package com.example.dbmysql.service.impl;


import com.example.dbmysql.mapper.roomHistoryMapper;
import com.example.dbmysql.pojo.RoomHistory;
import com.example.dbmysql.service.roomHistoryService;
import com.example.dbmysql.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;



@Service
public class roomHistoryServiceImpl implements roomHistoryService {


    @Autowired
    private roomHistoryMapper roomHistoryMapper;

    @Override
    public void NewRecording(RoomHistory roomHistory) {
        Map<String, Object> map = ThreadLocalUtil.get();

        String username = (String) map.get("username");

        roomHistory.setIssuingPerson(username);

        roomHistoryMapper.NewRecording(roomHistory);
    }

    @Override
    public void updateTime(RoomHistory roomHistory) {
        roomHistory.setIssuingTime(LocalDateTime.now().toString());
        roomHistoryMapper.updateTime(roomHistory);
    }

    @Override
    public void returnRoomByRoomName(RoomHistory roomHistory) {
        roomHistory.setReturnCardTime(LocalDateTime.now().toString());
        roomHistory.setStatus(3);
        roomHistoryMapper.returnRoomByRoomName(roomHistory);
    }
}
